<?php

	require_once('db_connect.php');
	$year = $_REQUEST['year'];
	$month = $_REQUEST['month'];
	$day = $_REQUEST['day'];
	
	if($year)
	{
		$sql = "SELECT * FROM connect_log WHERE TIME >=  '$year-01-01 00:00:00' AND TIME <  '$year-03-31 23:59:59'";
		$quarter1 = mysqli_num_rows(mysqli_query($conn,$sql));
		$sql = "SELECT * FROM connect_log WHERE TIME >=  '$year-04-01 00:00:00' AND TIME <  '$year-06-30 23:59:59'";
		$quarter2 = mysqli_num_rows(mysqli_query($conn,$sql));
		$sql = "SELECT * FROM connect_log WHERE TIME >=  '$year-07-01 00:00:00' AND TIME <  '$year-08-31 23:59:59'";
		$quarter3 = mysqli_num_rows(mysqli_query($conn,$sql));
		$sql = "SELECT * FROM connect_log WHERE TIME >=  '$year-09-01 00:00:00' AND TIME <  '$year-12-31 23:59:59'";
		$quarter4 = mysqli_num_rows(mysqli_query($conn,$sql));
			
		echo "<tr><img src=http://chart.apis.google.com/chart?cht=bvg&chco=4D89F9,C6D9FD&chbh=25,14,15&chs=250x200&chxt=x,y&chxl=0:|1분기|2분기|3분기|4분기&chtt=분기별+접속자+수&chts=4D89F9,20&chd=t:$quarter1,$quarter2,$quarter3,$quarter4><br><br><br><br></tr>";				
		
		for($i=1; $i< 13; $i++)
		{
			if($i==12)
				$sql="SELECT * FROM  `connect_log` WHERE TIME BETWEEN  '$year-$i-01 00:00:00' AND  '$year-$i-31 23:59:59'";
			else
				$sql="SELECT * FROM  `connect_log` WHERE TIME BETWEEN  '$year-$i-01 00:00:00' AND  '$year-$i-31 23:59:59'";
				
			$mon[$i]= mysqli_num_rows(mysqli_query($conn,$sql));		
			
		}			
		echo "<br><tr><img src=http://chart.apis.google.com/chart?cht=bvg&chco=FF28A7,C6D9FD&chbh=25,4&chs=700x200&chtt=월별+접속자+수&chts=FF28A7,20&chxt=x,y&chxl=0:|1월|2월|3월|4월|5월|6월|7월|8월|9월|10월|11월|12월|&chd=t:";
		for($i=1; $i< 13; $i++)
		{		
			if($i==12)
				echo $mon[$i]."><hr noshade>";
			else
				echo $mon[$i].",";
		}		
	
	}	
	if($year && $month)
	{
		for($i=1; $i<32; $i++)
		{
			$sql="SELECT * FROM  `connect_log` WHERE TIME BETWEEN  '$year-$month-$i 00:00:00' AND  '$year-$month-$i 23:59:59'";
			$d[$i] = mysqli_num_rows(mysqli_query($conn,$sql));
		}
		echo "<br><tr><img src=http://chart.apis.google.com/chart?cht=bvg&chco=9400D3,C6D9FD&chtt=일별+접속자+수&chts=9400D3,20&chbh=15,4&chs=850x200&chxt=x,y&chxl=0:";
		switch($month)
		{
			case 1 :
			case 3 :
			case 5 :
			case 7 :
			case 8 :
			case 10 :
			case 12 :
				for($i=1; $i <32; $i++)
					echo '|'.$i;
				echo '|&chd=t:';
				for($i=1; $i <32; $i++)
				{
					if($i==31)
						echo $d[$i];
					else
						echo $d[$i].',';
				}
				echo '></tr>';
				break;
			case 2 : 
				for($i=1; $i <29; $i++)
					echo '|'.$i;
				echo '|&chd=t:';
				for($i=1; $i <29; $i++)
				{
					if($i==28)
						echo $d[$i];
					else
						echo $d[$i].',';
				}
				echo '></tr>';
				break;
			default :
				for($i=1; $i <31; $i++)
					echo '|'.$i;
				echo '|&chd=t:';
				for($i=1; $i <31; $i++)
				{
					if($i==30)
						echo $d[$i];
					else
						echo $d[$i].',';
				}
				echo '></tr>';
				break;
		}
	}
	if($year && $month && $day)
	{
		for($i=0; $i<24; $i++)
		{
			$sql="SELECT * FROM  `connect_log` WHERE TIME BETWEEN  '$year-$month-$day $i:00:00' AND  '$year-$month-$day $i:59:59'";
				
			$t[$i] = mysqli_num_rows(mysqli_query($conn,$sql));
		}
		
		echo "<br><tr><img src=http://chart.apis.google.com/chart?cht=bvg&chco=006400,C6D9FD&chtt=시간대별+접속자+수&chts=006400,20&chbh=30,7&chs=1000x200&chxt=x,y&chxl=0:";
		for($i=0; $i <24; $i++)
			echo '|'.$i.'~'.($i+1);
			
		echo '|&chd=t:';
		for($i=0; $i <24; $i++)
		{
			if($i==23)
				echo $t[$i];
			else
				echo $t[$i].',';
		}
		echo '></tr>';
	}
?>